<template>
  <div>
    <el-dialog :title="info.title" :visible.sync="info.show">
      <el-form :model="form">
        <el-form-item label="所属角色" :label-width="formLabelWidth">
          <el-select v-model="form.roleid" placeholder="--请选择--">
            <!-- 遍历角色列表 -->
             <el-option v-for="item in role" :key="item.id" :label="item.rolename" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
         <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input type="password" v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
            <el-switch
                v-model="form.status"
                active-color="blue"
                inactive-color="grey" :active-value="1" :inactive-value="2">
              </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm" v-if="info.isAdd">添 加</el-button>
        <el-button type="primary" @click="update" v-else>修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {mapGetters,mapActions} from 'vuex'
import { addManager, oneManager, updateManager } from '../../../utils/request';
import { successAlert } from '../../../utils/alert';
export default {
  props:['info'],
  data(){
    return {
      formLabelWidth:'120px',
      form:{
        roleid:'',
        username:'',
        password:'',
        status:1,//1:正常 1:禁用
      }
    }
  },
  computed:{
    ...mapGetters({
      "role":"role/role"
    })
  },
  methods:{
    ...mapActions({
      "requestRole":"role/roleActions",
      "requestManager":"manager/managerActions",
      "requestCount":"manager/countActions",
    }),
    cancel(){
      this.info.show = false;
      this.form = {
        roleid:'',
        username:'',
        password:'',
        status:1,//1:正常 1:禁用
      }
    },
    confirm(){
        addManager(this.form).then(res=>{
          successAlert(res.data.msg)
          this.cancel()
          this.requestCount()
          this.requestManager()
        })
    },
    getDetail(uid){
      // 获取详情
      oneManager({uid}).then(res=>{
          this.form = res.data.list;
          this.form.password = '';
      })
    },
    update(){
      updateManager(this.form).then(res=>{
        successAlert(res.data.msg)
        this.cancel()
        this.requestManager()
      })
    }
  },
  mounted(){
    this.requestRole()
  }
}
</script>

<style>

</style>
